
<?php

$sort = $this->sort;
$sort_name = array("class"=>"","rel"=>"asc");
$sort_date = array("class"=>"","rel"=>"asc");
$sort_status = array("class"=>"","rel"=>"asc");
$sort_local = array("class"=>"","rel"=>"asc");
$sort_fullname = array("class"=>"","rel"=>"asc");
$sort_quantity = array("class"=>"","rel"=>"asc");
$sort_total_price = array("class"=>"","rel"=>"asc");
$sort_created_date = array("class"=>"","rel"=>"asc");

switch($sort['by']){
    case "article_name": 
        $sort_name = ($sort['type']=="asc")?array("class"=>" sorting_desc","rel"=>"desc"):array("class"=>" sorting_asc","rel"=>"asc");
        break;
    case "article_date": 
       $sort_date = ($sort['type']=="asc")?array("class"=>" sorting_desc","rel"=>"desc"):array("class"=>" sorting_asc","rel"=>"asc");
        break;
    case "article_status":
        $sort_status = ($sort['type']=="asc")?array("class"=>" sorting_desc","rel"=>"desc"):array("class"=>" sorting_asc","rel"=>"asc");
        break;
    case "article_local": 
        $sort_local = ($sort['type']=="asc")?array("class"=>" sorting_desc","rel"=>"desc"):array("class"=>" sorting_asc","rel"=>"asc");
        break;
    case "fullname": 
        $sort_fullname = ($sort['type']=="asc")?array("class"=>" sorting_desc","rel"=>"desc"):array("class"=>" sorting_asc","rel"=>"asc");
        break;
    case "quantity": 
        $sort_quantity = ($sort['type']=="asc")?array("class"=>" sorting_desc","rel"=>"desc"):array("class"=>" sorting_asc","rel"=>"asc");
        break;
    case "total_price": 
        $sort_total_price = ($sort['type']=="asc")?array("class"=>" sorting_desc","rel"=>"desc"):array("class"=>" sorting_asc","rel"=>"asc");
        break;
    case "created_date": 
        $sort_created_date = ($sort['type']=="asc")?array("class"=>" sorting_desc","rel"=>"desc"):array("class"=>" sorting_asc","rel"=>"asc");
        break;
        
}

?>
<table class="data display datatable" >
    <thead>
        <tr>
            <th class="center">STT</th> 
            <th class="sorting<?=$sort_fullname['class']?>"><a href="<?=$this->url(array("module"=>"admin","controller"=>"orders","action"=>"list","sortby"=>"fullname"))?>" rel="<?=$sort_fullname["rel"]?>" > Khách hàng </a></th>
            <th class="sorting<?=$sort_quantity['class']?>"> 
                <a href="<?=$this->url(array("module"=>"admin","controller"=>"orders","action"=>"list","sortby"=>"quantity"), null, true)?>" rel="<?=$sort_quantity["rel"]?>" >Số lượng</a>
            </th>
            <th width="120" class="sorting<?=$sort_total_price['class']?>">
                <a href="<?=$this->url(array("module"=>"admin","controller"=>"orders","action"=>"list","sortby"=>"total_price"), null, true)?>" rel="<?=$sort_total_price["rel"]?>">Tổng tiền</a>
            </th>
            
            <th width="150" class="center sorting<?=$sort_created_date['class']?>">
                <a href="<?=$this->url(array("module"=>"admin","controller"=>"orders","action"=>"list","sortby"=>"created_date"), null, true)?>" rel="<?=$sort_created_date["rel"]?>">Ngày đặt hàng</a>
            </th>
            <th width="50" class="center">Xem</th>
        </tr>                   
    </thead>
    <tbody>
            <?php $stt=1; foreach($this->datas as $rows){
        $parity = ($stt%2)?"odd":"even";?>
                   <tr class="gradeA <?=$parity?>" >
                       <td class="center"><?=$rows->id?></td>
                       <td><?=$rows->fullname?></td>
                       <td><?=$rows->quantity?></td>
                       <td>$<?=number_format($rows->total_price,2,'.','')?></td>
                       <td><?php
                       $zdate = new Zend_Date($rows->created_date);
                       echo $zdate->toString("dd/MM/Y H:m:s");
                       
                       ?></td>
                       <td><a class="order-view" href="<?=$this->url(array("module"=>"admin","controller"=>"orders","action"=>"detail","id"=>"$rows->id"))?>" >Xem</a></td>
                   </tr>
            <?php } ?>
    </tbody>
    
</table>
<?php if($this->datas->count()>1){// Nhiều hơn 1 trang thì sử dụng phân trang?>
<div class="dataTables_paginate paging_full_numbers">
    
           
    <?=$this->paginationControl($this->datas,"Sliding","partial/pagination-control.phtml")?>
        
</div>

<?php }?>
 <div class="clear"></div>
<div class="dialog-message" title="Thông báo" style="display: none;"></div>

<script>
$(function(){
        
    /*Xóa bài viết*/
   /* $(".del").click(function(){
        var _this = $(this);
        $(".dialog-message").html("<div class='message warning'><h5>Cảnh báo</h5><p>Bạn có chắc muốn thực hiện hành động này không?</p></div>")
            .dialog({            
                autoOpen: true,
                modal: true,
                buttons: {
                    "Có": function(){                    
                        var link =  _this.attr("href");
                        _this.parent("td").parent("tr").remove();
                        $.get(link,{},function(){},"json");
                        $(this).dialog("close");
                    },
                    "Không": function(){
                        $(this).dialog("close");
                    }
                }
            })
        return false;
    })
    */
     /*Phân trang*/
    $(".pagination a").click(function(){
        var link = $(this).attr("href");
        $(".loading").show();
        $.get(link,null,function(rdata){
            $(".dataTables_wrapper").html(rdata);
            $(".loading").fadeOut(1000);
        })
        return false;
    })
    
    /*Sắp xếp*/
    $(".sorting a").click(function(){
        var link = $(this).attr("href");
        var type = $(this).attr("rel");
        var filter_value = $(".searchkey").val();
        var sdata = {"sorttype":type,"filter_field":"name","filter_value":filter_value};
        if(filter_value.length==0){
            sdata={"sorttype":type};
        }
        $(".loading").show();
        $.post(link,sdata,function(rdata){
            $(".dataTables_wrapper").html(rdata);
            $(".loading").fadeOut(1000);
        })
        return false;
    })
    
    /*thay đổi trạng thái*/
    $(".choice-multi").click(function(){
        var icon = $(this).children("img").attr("src");
        var status = $(this).attr("rel");
        var link = $(this).attr("href");
        if(status==0){            
            var n_icon = icon.replace("star_unlist","star_list");
            $(this).attr("rel",1);
        }else{
            var n_icon = icon.replace("star_list","star_unlist");
            $(this).attr("rel",0);
        }
        $(this).children("img").attr("src",n_icon);
        $.get(link,{},function(){},"json");
        return false;
    })
    /*fancybox*/
    

})
</script>